package com.monai.aidati.mq;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class TtlProducer {
    private final static String QUEUE_NAME = "ttl_queue";

    public static void main(String[] args) throws Exception{
        ConnectionFactory factory=new ConnectionFactory();
        factory.setHost("localhost");
        factory.setUsername("admin");
        factory.setPassword("admin");
        try (Connection connection=factory.newConnection();
             Channel channel=connection.createChannel()){
            channel.queueDeclare(QUEUE_NAME,true,false,false,null);
            String message = "Hello World!";
            AMQP.BasicProperties basicProperties=new AMQP.BasicProperties().builder()
                    .expiration("10000")
                    .build();
            channel.basicPublish("",QUEUE_NAME,basicProperties,message.getBytes("utf8"));
        }

    }

}
